/*
 *author: macro gu
 *email: macrogu@hotmail.com
 *
 * */

#pragma once

#include <tinyxml.h>
#include <string>
#include <vector>
#include <map>
#include "log.h"
#include "singleton.h"
#include "message.h"

// local server info
struct stServerInfo
{
	std::string serverIp;
	unsigned int port;
	unsigned int backlog;
	unsigned int maxevents;
};

// email smtp server info
struct stSmtpInfo
{
	std::string cSmtpServer;        // smtp server address
	unsigned int uiPort;            // smtp server port
	std::string cUsername;          // send email user name
	std::string cPassword;          // send email user password
};

// mysql info
struct stMysqlInfo
{
	std::string cMysqlAddr;
	unsigned int uiPort;
	std::string cDatabase;		
	std::string cUsername;
	std::string cPassword;
};

// fastdfs info
struct stFastDfsInfo
{
	std::string cClientCfg;
	std::string cDomain;
};

class CAllConfigure : public ISingleton<CAllConfigure>
{
	public:

		// load all configure by conf file 
		bool loadConf();
		// if load conf file right return true
		bool hasLoadConfRight();
		// set configure status ,

		// get local server configuration
		const stServerInfo GetLocalServerConfiguration();
		// get SMTP server configuration
		const stSmtpInfo GetSmtpServerConfiguration();
		// get Mysql Server configuration
		const stMysqlInfo GetMysqlServerConfiguration();
		// get FastDfs info configuration
		const stFastDfsInfo GetFastDfsConfiguration();

	protected:
		// load local server configure
		bool LoadServerInfo(const std::string& fileDir);
		// load smtp server configure
		bool LoadSmtpServerInfo(const std::string& fileDir);
		// load Mysql server configure
		bool LoadMysqlInfo(const std::string& fileDir);
		// load fastdfs configure
		bool LoadFastDfsInfo(const std::string& fileDir);

	private:
		// if all configuration has be loaded right
		bool bAllConfLoadedRight;
		// configure file path
		std::string cConfFilePath;
		// local server configuration
		stServerInfo m_LocalServerInfo;
		// smtp server configuration
		stSmtpInfo  m_SMTPServerInfo;
		// mysql server configuration
		stMysqlInfo m_MysqlServerInfo;
		// fastdfs configuration
		stFastDfsInfo m_FastDfsInfo;

		friend ISingleton<CAllConfigure>;
		friend class std::auto_ptr<CAllConfigure>;

		CAllConfigure();

		~CAllConfigure();
};
